<template>
    
     <div class="page user-select multi-select" v-show="searchInput.length&&searchResultList.length">
        <ul class="list com-border-top com-border-bottom">
            <li class="weui-cells_checkbox" v-for="member in searchResultList">
                <label class="touch" for="{{member.user_id}}">
                    <input class="weui-check" type="checkbox" value="{{member.user_id}}"  id="{{member.user_id}}" v-model="selectMemberList">
                    <i class="weui-icon-checked"></i>
                    <img v-if="member.logo.thumb_url!=''" class="avatar" :src="member.logo.thumb_url">
                    <img v-if="member.logo.thumb_url==''" class="avatar" src="../../static/imgs/avatar.png">
                    <div class="info com-border-bottom">
                        <p class="title"><span class="tag tag_1" v-if="member.identity_str!='成员'" 
                                  :class="{'tag tag_1':member.identity_str=='管理员'||member.identity_str=='超级管理员',
                                           'tag tag_2':member.identity_str=='组长'}">{{member.identity_str}}</span>{{member.nick_name}}
                        </p>
                    </div>
                </label>
            </li>
        </ul>
        <div class="count bg-color com-border-top">
            <span class="num">已选择：<em>{{selectMemberList.length}}人</em></span>
            <a class="mod-btn-s-1" @click="submitResult">确定</a>
        </div>
    </div>
    <div v-show="!searchInput.length" class="mod-empty new_mod-empty">
        <div class="search_tip">你可以搜索</div>
        <div class="searchName">
            <img src="../../static/imgs/icons/icon_8.png" class="searchName_img">
            <p class="searchName_tip">姓名</p>
        </div>
        <div class="line"></div>
        <div class="searchPhone">
            <img src="../../static/imgs/icons/icon_9.png" class="searchPhone_img">
            <p class="searchPhone_tip">手机号</p>
        </div>

    </div>
    <div v-show="searchResultList.length==0" class="mod-empty new_mod-empty">
        <div class="icon icon_4"></div>
        <p class="tip">什么都没有搜到耶</p>
    </div>

</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */

    import tabbar from 'vux/dist/components/tabbar'
    import cache from 'gapi/cache.js'
    import commonPage from 'clientApi/commonPage.js'
    import searchPage from 'clientApi/searchPage.js'
    import * as util from 'js/util.js'
    import Empty from 'components/Empty/Empty'

    /**
     *  组件实例对象
     */
    export default {
        components: {
            tabbar,
            Empty
        },
        data: function(){
            return{
               searchInput:'',
               searchResult:[],
               selectMemberList:[],
               allMemberList:[],
               origin_type: '',//判断是从考勤还是位置监控进入
            }
        },
        computed:{
            searchResultList(){
                let searchResultList = []
                this.allMemberList.forEach((item)=>{
                    if(item.nick_name.indexOf(this.searchInput)>-1 || item.mobile.indexOf(this.searchInput)>-1 || item.name_pinyin.indexOf(this.searchInput)>-1){
                        searchResultList.push(item)
                    }
                })
                console.log(searchResultList)
                // alert(JSON.stringify(searchResultList))
                return searchResultList
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){   
                
                this.origin_type = util.getUrddataString('origin_type') 
                cache.getMemoryCache('participantMember', (data) => {
                    if(data){
                        this.selectMemberList = data
                    }
                })
                cache.getMemoryCache('allMemberList', (data) => {
                    console.log(data)
                    if(data){
                        this.allMemberList = data
                    }
                })
                window.getSearchResult=(data)=>{
                    this.searchInput = data
                }
            },
            submitResult() {

                var participantMember = this.selectMemberList
                if (util.getUrddataString('is_move') && util.getUrddataString('is_move') == 0 || util.getUrddataString('is_move') == 1) {
                    commonPage.goBack(1,{'key':'selectM','value':participantMember,'pream':util.getUrddataString('is_move')})
                } else {
                    cache.getMemoryCache('webViewID',(data)=>{
                        if(data){                            
                            if(this.origin_type == 'sign'){
                              let sign_participantMember = {
                                participantMember_userId: participantMember,
                                participantMember_groupNum: 0,
                                participantMember_userNum: this.selectMemberList.length
                              }             
                              commonPage.goBack(1,{'key':'participantMember','value':sign_participantMember},data.webViewID)
                            }else{
                              commonPage.goBack(1,{'key':'participantMember','value':participantMember},data.webViewID)
                            }
                          }
                    })
                }
                
            }
        },
        created(){
            this.init()
        }
        
    }

    
</script>

<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/common.css"></style>
<style src="../../static/css/user-list.css"></style>